home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
shazam.exe
/
GEDITOR.IMP
< prev
next >
Wrap
Text File
|
1992-09-01
|
18KB
|
494 lines
{*******************************************************************
GEDITOR.IMP
*******************************************************************}
{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
EDITOR-SPECIFIC
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
{===================================================================
EXTENT - return "cascaded" extent of current or first TWindow
===================================================================}
procedure FirstExtent ( VAR R : TRect ) ;
begin
DeskTop^.GetExtent ( R ) ;
if Desktop^.Current = NIL then EXIT ;
if not Desktop^.Current^.GetState ( sfVisible ) then EXIT ;
Desktop^.Current^.GetBounds ( R ) ;
if R.B.X - R.A.X > MinWinSize.X then
inc ( R.A.X ) ;
if R.B.Y - R.A.Y > MinWinSize.Y then
inc ( R.A.Y ) ;
end ;
{===================================================================
EXTENT - return "cascaded" extent of current or first TEditWindow
===================================================================}
procedure FirstExtentEd ( VAR R : TRect ) ;
{-------------------------------------------------------------------
CURRENT
-------------------------------------------------------------------}
function Test ( P : PView ) : boolean ; FAR ;
begin
Test := FALSE ;
if TypeOf ( P^ ) <> TypeOf ( TEditWindow ) then EXIT ;
with PEDITWINDOW ( P )^.Editor^ do
begin
if not P^.GetState ( sfVisible ) then EXIT ;
P^.GetBounds ( R ) ;
Test := TRUE ;
if R.B.X - R.A.X > MinWinSize.X then
inc ( R.A.X ) ;
if R.B.Y - R.A.Y > MinWinSize.Y then
inc ( R.A.Y ) ;
end ;
end ;
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PROCESS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
begin
DeskTop^.GetExtent ( R ) ;
Desktop^.FirstThat ( @Test ) ;
end ;
{===================================================================
NUMBER
===================================================================}
function WinNumExist ( WinNum : integer ) : boolean ;
{-------------------------------------------------------------------
-------------------------------------------------------------------}
function Test ( P : PView ) : boolean ; FAR ;
begin
Test := FALSE ;
if not Selectable ( P ) then EXIT ;
Test := WinNum = PWINDOW ( P )^.Number ;
end ;
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PROCESS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
begin
WinNumExist := Desktop^.FirstThat ( @Test ) <> NIL ;
end ;
{===================================================================
NUMBER
===================================================================}
function NextWinNum : integer ;
var
i : integer ;
begin
for i := 1 to 9 do
if not WinNumExist ( i ) then
begin
NextWinNum := i ;
EXIT ;
end ;
NextWinNum := wnNoNumber ;
end ;
{===================================================================
Opens a window, with choice of whether visible.
Sets "AutoIndent" on. If NewEdit, set wrap & right margin.
===================================================================}
function OpenEditor ( FileName : FNameStr ;
Visible : boolean ) : PEditWindow ;
var
P : PView ;
R : TRect ;
begin
OpenEditor := NIL ;
if Visible then
FirstExtentEd ( R )
else
DeskTop^.GetExtent ( R ) ;
P := Application^.ValidView (
New ( PEditWindow ,
Init ( R , FileName, NextWinNum ) ) ) ;
if P = NIL then EXIT ;
with PEDITWINDOW ( P )^ do
begin
if not Visible then
Hide ;
Editor^.AutoIndent := TRUE ;
{$IFDEF newedit }
Editor^.Word_Wrap := Default_Word_Wrap ;
Editor^.Right_Margin := Default_Line_Length ;
{$ENDIF }
end ;
DeskTop^.Insert ( P ) ;
OpenEditor := PEDITWINDOW ( P ) ;
end ;
{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SAVE/CLOSE
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
{===================================================================
IF CHANGED
===================================================================}
procedure SaveEdModified ;
var
Count : byte ;
{-------------------------------------------------------------------
-------------------------------------------------------------------}
procedure DoThis ( P : PView ) ; FAR ;
begin
if TypeOf ( P^ ) <> TypeOf ( TEditWindow ) then EXIT ;
with PEDITWINDOW ( P )^.Editor^ do
begin
if not Modified then EXIT ;
SetBorder ( 14 ) ; { YELLOW - busy }
Save ;
inc ( Count ) ;
end ;
end ;
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PROCESS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
begin
Count := 0 ;
Desktop^.ForEach ( @DoThis ) ;
if Count > 0 then
SetBorder ( 0 ) ; { BLACK - done }
end ;
{===================================================================
ALWAYS A DIALOG FOR NAME
===================================================================}
procedure SaveEdUntitled ;
{-------------------------------------------------------------------
-------------------------------------------------------------------}
procedure DoThis ( P : PView ) ; FAR ;
begin
if TypeOf ( P^ ) <> TypeOf ( TEditWindow ) then EXIT ;
with PEDITWINDOW ( P )^.Editor^ do
begin
if not Modified then EXIT ;
if FileName <> '' then EXIT ;
P^.MakeFirst ; { bring to front }
SaveAs ;
end ;
end ;
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PROCESS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
begin
Desktop^.ForEach ( @DoThis ) ;
end ;
{===================================================================
CLOSE - "Untitled" TEditWindow(s). Must force "Modified" flag,
since cmClose won't work if ^. Valid returns FALSE.
===================================================================}
procedure CloseEdUntitled ;
{-------------------------------------------------------------------
-------------------------------------------------------------------}
procedure DoThis ( P : PView ) ; FAR ;
begin
if TypeOf ( P^ ) <> TypeOf ( TEditWindow ) then EXIT ;
with PEDITWINDOW ( P )^.Editor^ do
begin
if FileName <> '' then EXIT ;
Modified := FALSE ;
end ;
Message ( P , evCommand , cmClose , NIL ) ;
end ;
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PROCESS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
begin
Desktop^.ForEach ( @DoThis ) ;
end ;
{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CLIP BOARD
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
{===================================================================
CREATE
===================================================================}
procedure CreateClipboard ;
var
R : TRect ;
begin
if not BuffersInUse then EXIT ;
ClipWindow := OpenEditor ( '' , FALSE ) ;
if ClipWindow = NIL then EXIT ;
Clipboard := ClipWindow^.Editor ;
Clipboard^.CanUndo := FALSE ;
ClipWindow^.HelpCtx := SaveCl